let last = 0;
const vendors = ['ms', 'moz', 'webkit', 'o'];
for (let i = 0, len = vendors.length; i < len && !window.requestAnimationFrame; i++) {
  window.requestAnimationFrame = window[vendors[i] + 'RequestAnimationFrame'];
  window.cancelAnimationFrame = window[vendors[i] + 'CancelAnimationFrame'] || window[vendors[i]+'CancelRequestAnimationFrame'];
}
function raf(callback) {
  const current = +new Date();
  const delay = Math.max(0, 16 - (current - last));
  const id = window.setTimeout(function() { callback(current + delay); }, delay);
  last = current + delay;
  return id;
}
if (!window.requestAnimationFrame) {
  window.requestAnimationFrame = raf;
}
if (!window.cancelAnimationFrame) {
  window.cancelAnimationFrame = function(id) {
    window.clearTimeout(id);
  };
}
